/*
 * @Description: 元数据相关接口
 * @Author: Rfan
 * @Date: 2022-01-24 14:36:22
 * @LastEditTime: 2022-06-21 14:55:56
 */

import request, { configRequest } from '@/utils/request';

// 通过单位ID查询全宗
export function searchFetchFields(data) {
  return request({
    url: `/query-metadata/`,
    method: 'post',
    data
  });
}

// 查询表结构，参数：{metadataFieldType: number; coordinate: ICoordinate}
export function fetchMetadata(data) {
  return configRequest({
    url: `/metadata/query`,
    method: 'post',
    data
  });
}

// 增加档案类型表结构
export function addMetadata(data) {
  return configRequest({
    url: `/metadata/field`,
    method: 'post',
    data
  });
}

// 增加档案类型表结构
export function editMetadataBusinessById(data) {
  return configRequest({
    url: `/metadata/field`,
    method: 'put',
    data
  });
}

// 增加档案类型表结构
export function deleteMetadata(data) {
  return configRequest({
    url: `/metadata/field`,
    method: 'delete',
    data
  });
}

// 查询增加档案条目字段
export function fetchArchiveProp(params) {
  return request({
    url: `/archives/query/add-archive-property-data`,
    method: 'get',
    params
  });
}

// 查询档案条目
export function searchArchivesLevel({ archiveTypeId, level }) {
  return request({
    url: `/archives/query/${archiveTypeId}/${level}`,
    method: 'get'
  });
}

// ----------------------------------
/**
 * @description: 别名相关接口
 */
// 查询别名列表
export function fetchAliasList(data = {}) {
  return configRequest({
    url: `archive-business-concept/list`,
    method: 'post',
    data
  });
}

// 分页查询别名
export function fetchAliasListByPage(data) {
  return configRequest({
    url: `archive-business-concept/page`,
    method: 'post',
    data
  });
}

// 新增别名
export function addAlias(data) {
  return configRequest({
    url: `/archive-business-concept/`,
    method: 'post',
    data
  });
}

// 编辑别名
export function editAlias(data) {
  return configRequest({
    url: `/archive-business-concept/`,
    method: 'put',
    data
  });
}

// 删除别名
export function deleteAlias(id) {
  return configRequest({
    url: `/archive-business-concept/${id}`,
    method: 'delete'
  });
}

// ----------------------------------
/**
 * @description: 关联相关接口
 */
// 分页查询关联关系列表
export function fetchRelationListByPage(data) {
  return configRequest({
    url: `/metadata-relation/page`,
    method: 'post',
    data
  });
}

// 增加关联关系
export function addRelation(data) {
  return configRequest({
    url: `/metadata-relation/`,
    method: 'post',
    data
  });
}

// 编辑关联关系
export function editRelation(data) {
  return configRequest({
    url: `/metadata-relation/`,
    method: 'put',
    data
  });
}

// 删除关联关系
export function deleteRelation(id) {
  return configRequest({
    url: `/metadata-relation/${id}`,
    method: 'delete'
  });
}

// ----------------------------------
/**
 * @description: 关联相关接口
 */
// 分页查询继承列表
export function fetchInheritListByPage(data) {
  return new Promise((resolve, reject) => {
    fetchRelationListByPage({ ...data, param: { ...data.param, relationType: 0 } })
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}

// 增加继承
export function addInherit(data) {
  return new Promise((resolve, reject) => {
    addRelation({ ...data, relationType: 0 })
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}

// 编辑继承
export function editInherit(data) {
  return new Promise((resolve, reject) => {
    editRelation({ ...data, relationType: 0 })
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}

// 删除关联关系
export function deleteInherit(id) {
  return new Promise((resolve, reject) => {
    deleteRelation(id)
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}

// ----------------------------------
/**
 * @description: 依赖相关接口
 */
// 分页查询依赖列表
export function fetchRelyListByPage(data) {
  return new Promise((resolve, reject) => {
    fetchRelationListByPage({ ...data, param: { ...data.param, relationType: 1 } })
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}

// 增加依赖
export function addRely(data) {
  return new Promise((resolve, reject) => {
    addRelation({ ...data, relationType: 1 })
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}

// 编辑依赖
export function editRely(data) {
  return new Promise((resolve, reject) => {
    editRelation({ ...data, relationType: 1 })
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}

// 删除依赖关系
export function deleteRely(id) {
  return new Promise((resolve, reject) => {
    deleteRelation(id)
      .then((res) => {
        resolve(res);
      })
      .catch((err) => reject(err));
  });
}
